package srx.open.com.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.listener.SaveListener;
import srx.open.com.R;
import srx.open.com.bean.FeedBack;
import srx.open.com.bean.User;
import srx.open.com.utils.OpenToast;
import srx.open.com.utils.UserUtils;

/**
 * 消息反馈界面.
 */
public class FeedBackMsgActivity extends ExtendBaseActivity {

    @Bind(R.id.right_lay)
    View right_lay;
    @Bind(R.id.left_tv)
    TextView left_tv;
    // 反馈
    @Bind(R.id.sendmessage_et)
    EditText sendmessage_et;

    @Override
    public void initAllDatas() {
    }

    @Override
    public void initAllViews() {
        setContentView(R.layout.activity_feedback_msg);
        ButterKnife.bind(this);
        initTitls();
    }

    private void initTitls() {
        right_lay.setVisibility(View.INVISIBLE);
        left_tv.setText("反馈");
    }

    /**
     * 返回.
     */
    @OnClick(R.id.left_lay)
    void left_lay(View view) {
        finish();
    }

    /**
     *  发送反馈信息.
     */
    @OnClick(R.id.send_btn)
    void send_btn(View view) {
        String content = sendmessage_et.getText().toString();
        if (!TextUtils.isEmpty(content)) {
            FeedBack feedBack = new FeedBack();
            feedBack.setContent(content);
            User user = UserUtils.getCurrentUser(mContext);
            // 添加关联的反馈用户.
            if (user != null) {
                feedBack.setUsertt(user);
            }
            feedBack.save(mContext, new SaveListener() {
                @Override
                public void onSuccess() {
                    OpenToast.showMsg("反馈成功");
                    finish();
                }

                @Override
                public void onFailure(int i, String s) {
                    OpenToast.showMsg("反馈失败");
                }
            });
        } else {
            OpenToast.showMsg("反馈的内容不能为空");
        }
    }

}
